package im

import (
	"dhfshop/controllers/base"
	"dhfshop/domain/im"
	"github.com/astaxie/beego"
	"wxsdk/miniapp/utils/security"
)

type NotifyController struct {
	base.BaseController
}
// 授权事件接收服务，对应审核资料中授权事件接收URL,比如:component_verify_ticket,authorized,unauthorized
func (this *NotifyController) AcceptAuthorizeEvent() {
	isvToken := beego.AppConfig.String("IsvToken")
	isvAESKey := beego.AppConfig.String("IsvAESKey")
	isvAppId := beego.AppConfig.String("IsvAppId")
	timestamp := this.GetString("timestamp")
	nonce := this.GetString("nonce")
	msgSignature := this.GetString("msg_signature")
	if timestamp == "" || nonce == "" || msgSignature == "" {
	    this.Ctx.WriteString("parameter is fail")
		return
	}
	reqMap, err := security.DecrypterXmlToMap(isvToken,isvAESKey,isvAppId,timestamp,nonce,msgSignature,this.Ctx.Input.RequestBody)
	if err != nil {
		beego.Emergency("DecrypterXmlToMap error: " + err.Error())
		return
	}
	reqMap["LocalKind"] =  "AUTHORIZE_EVENT"
	imlayer.PushMsgSvrIns.PushDao <- &reqMap
	//
	this.Ctx.WriteString("success")
}
